import numpy as np
from scipy.spatial.distance import euclidean, cityblock, chebyshev

# 1. 数据生成：模拟点集
np.random.seed(42)
num_points = 5  # 点的数量
dimensions = 3  # 数据维度

# 随机生成点集
point_set = np.random.randint(0, 10, (num_points, dimensions))
target_point = np.random.randint(0, 10, (1, dimensions))

# 2. 距离度量函数
def calculate_distances(point_set, target_point):
    """ 
    计算点集与目标点的欧氏距离、曼哈顿距离和切比雪夫距离
    """ 
    results = []
    for point in point_set:
        euclidean_dist = euclidean(point, target_point[0])  # 欧氏距离
        manhattan_dist = cityblock(point, target_point[0])  # 曼哈顿距离
        chebyshev_dist = chebyshev(point, target_point[0])  # 切比雪夫距离
        results.append((euclidean_dist, manhattan_dist, chebyshev_dist))
    return results

# 3. 计算距离
distances = calculate_distances(point_set, target_point)

# 4. 输出结果
print("点集（随机生成）:")
print(point_set)
print("\n目标点:")
print(target_point[0])
print("\n各点与目标点的距离:")
print(f"{'点索引':<10} {'欧氏距离':<15} {'曼哈顿距离':<15} {'切比雪夫距离':<15}")
for i, (euc, man, cheb) in enumerate(distances):
    print(f"{i:<10} {euc:<15.4f} {man:<15.4f} {cheb:<15.4f}")